<template>
  <div class="container">
    <el-header class="header">
      <el-button class="back" @click="goBack">
        <el-icon>
          <ArrowLeft />
        </el-icon>
      </el-button>
      <el-tabs class="choose" v-model="activeName" @tab-click="choosePage">
        <el-tab-pane label="上下班打卡" name="clockInOrOut"></el-tab-pane>
        <el-tab-pane label="我的考勤" name="myRecords"></el-tab-pane>
        <el-tab-pane label="部门考勤" name="othersRecords"></el-tab-pane>
      </el-tabs>
    </el-header>

    <el-main class="main-content">
      <router-view></router-view>
    </el-main>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();
const activeName = ref("clockInOrOut"); // 默认值

// 根据当前路由设置激活的标签
onMounted(() => {
  const pathParts = route.path.split("/");
  const currentTab = pathParts[pathParts.length - 1];
  if (["clockInOrOut", "myRecords", "othersRecords"].includes(currentTab)) {
    activeName.value = currentTab;
  }
});

const goBack = () => {
  router.push("/betch");
};

const choosePage = (tab) => {
  // 确保路径与路由配置一致
  router.push(`/attendance/${tab.props.name}`);
};
</script>

<style scoped>
.container {
  height: 100vh;
  width: 100vw;
  background-color: #e1efff;
  overflow-x: hidden;
  /* 添加相对定位 */
  position: relative;
}

.header {
  height: 8vh;
  width: 100%;
  background-color: white;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 添加固定定位 */
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  /* 确保在最上层 */
}

.main-content {
  /* 添加顶部内边距等于header高度 */
  padding-top: 8vh;
  overflow-y: auto;
  /* 允许内容滚动 */
}

.back {
  position: absolute;
  left: 0;
  top: 3vh;
  border: none;
  font-size: 24px;
  background: transparent;
}

.choose {
  position: relative;
  top: 1vh;
}

:deep(.choose .el-tabs__header) {
  margin: 0;
}

:deep(.choose .el-tabs__nav-wrap) {
  justify-content: center;
}
</style>